﻿using System;
using System.Collections.Generic;
using DbConnect;
using DbConnect.Sql;

namespace DnDEngine.Download
{
    public class DownloadManager
    {
        private List<Class.Download> _downloads;

        public DownloadManager()
        {
            _downloads = new List<Class.Download>();
            Load();
        }

        #region "Private functions"

        private void Load()
        {
            //Make a select on all downloads and fill _downloads.

            try
            {
                Logger.Log.TraceAction("DownloadManager.Load", "");
                var data = new DbConnect.DataAccess();
                var req = SqlRequest.Select + SqlDownload.ID + SqlRequest.From + SqlDownload.TableName;

                var table = data.Select(req);

                if (table != null && table.Rows.Count > 0)
                {
                    foreach (System.Data.DataRow row in table.Rows)
                    {
                        _downloads.Add(new Class.Download(DbConnect.CoolFunctions.GetIntValue(row, "ID")));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.TraceError("DownloadManager.Load", ex);
            }
            finally
            {
            }
           
        }

        #endregion
    }
}
